package defpackage; import android.support.v4.app.NotificationCompat; import android.text.TextUtils; import cn.wps.moffice.OfficeApp; import com.baidu.tts.loopj.AsyncHttpResponseHandler; import com.iflytek.cloud.SpeechEvent; import defpackage.vyt; import defpackage.vyu; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.scribe.model.OAuthConstants; /* renamed from: eao reason: default package */ public final class eao { vyt ewB; String mToken; /* access modifiers changed from: package-private */ /* renamed from: eao$a */ public static class a extends vzu { private String dDh; private Map<String, String> ewG; public a(int i, String str, String str2, c<JSONObject> cVar) { this(i, str, null, str2, cVar); } public a(int i, String str, String str2, String str3, final c<JSONObject> cVar) { this(i, str, str2, str3, new vyu.b<String>() { /* class defpackage.eao.a.AnonymousClass1 */ /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // defpackage.vyu.b public final /* synthetic */ void onResponse(String str) { String str2 = str; if (c.this != null) { a.b(str2, c.this); } } }, new vyu.a() { /* class defpackage.eao.a.AnonymousClass2 */ @Override // defpackage.vyu.a public final void a(vyz vyz) { if (c.this != null) { c.this.c(vyz); } } }); } private a(int i, String str, String str2, String str3, vyu.b<String> bVar, vyu.a aVar) { super(i, str, bVar, aVar); this.ewG = new HashMap(); this.dDh = str2; this.ewG.put("token", str3); } public a(int i, String str, String str2, final vzt<JSONObject> vzt) { this(0, str, str2, new c<JSONObject>() { /* class defpackage.eao.a.AnonymousClass3 */ @Override // defpackage.eao.c public final void c(Throwable th) { vzt.this.a(new vyz(th.getCause())); } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // defpackage.eao.c public final /* synthetic */ void y(JSONObject jSONObject) { vzt.this.onResponse(jSONObject); } }); } static /* synthetic */ void b(String str, c cVar) { try { JSONObject jSONObject = new JSONObject(str); if (!jSONObject.has(OAuthConstants.CODE) || jSONObject.getInt(OAuthConstants.CODE) == 0) { cVar.y(jSONObject); } else { cVar.c(new b(jSONObject.getInt(OAuthConstants.CODE))); } } catch (JSONException e) { cVar.c(e); } } @Override // defpackage.vys public final byte[] getBody() throws vyz { try { return this.dDh.getBytes(AsyncHttpResponseHandler.DEFAULT_CHARSET); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return this.dDh.getBytes(); } } @Override // defpackage.vys public final String getBodyContentType() { return "application/json; charset=" + AsyncHttpResponseHandler.DEFAULT_CHARSET; } @Override // defpackage.vys public final Map<String, String> getHeaders() throws vyz { return this.ewG; } } /* renamed from: eao$b */ public static class b extends Exception { int ewH; public b(int i) { this.ewH = i; } public final String getMessage() { switch (this.ewH) { case -4: return "任务已满"; case -3: return "服务器处理出错"; case -2: return "参数不合法"; case -1: return "token过期"; case 0: default: return "未知错误"; case 1: return "设备不在线"; } } } /* renamed from: eao$c */ public interface c<T> { void c(Throwable th); void y(T t); } private JSONObject aA(String str, String str2) throws ExecutionException, InterruptedException { vzt fVu = vzt.fVu(); a(new a(0, TextUtils.join("/", new String[]{"https://moapi.wps.cn/printerServe/v1", TextUtils.join("/", new String[]{"printers", str, "tasks", str2})}), this.mToken, fVu), str2); do { } while (!fVu.isDone()); try { return ((JSONObject) fVu.get()).getJSONObject(SpeechEvent.KEY_EVENT_RECORD_DATA); } catch (JSONException e) { return null; } } protected static List<String> e(JSONArray jSONArray) { if (jSONArray == null || jSONArray.length() == 0) { return Collections.emptyList(); } int length = jSONArray.length(); ArrayList arrayList = new ArrayList(jSONArray.length()); for (int i = 0; i < length; i++) { try { arrayList.add(jSONArray.get(i).toString()); } catch (JSONException e) { lvf.dxt(); lvf.dxw(); } } return arrayList; } public final Object a(String str, final c<List<String>> cVar) { String join = TextUtils.join("/", new String[]{"printers", str}); return a(new a(0, TextUtils.join("/", new String[]{"https://moapi.wps.cn/printerServe/v1", join}), this.mToken, new c<JSONObject>() { /* class defpackage.eao.AnonymousClass1 */ @Override // defpackage.eao.c public final void c(Throwable th) { if (cVar != null) { cVar.c(th); } } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // defpackage.eao.c public final /* synthetic */ void y(JSONObject jSONObject) { try { JSONArray jSONArray = jSONObject.getJSONArray(SpeechEvent.KEY_EVENT_RECORD_DATA); if (cVar != null) { cVar.y(eao.e(jSONArray)); } } catch (JSONException e) { c(e); } } }), "printers"); } public final Object a(String str, String str2, String str3, int i, int i2, final c<String> cVar) { JSONObject jSONObject = new JSONObject(); try { jSONObject.put("fileUrl", str2); jSONObject.put("printer", str3); jSONObject.put("copies", i); jSONObject.put("appType", i2); } catch (JSONException e) { cVar.c(e); } String join = TextUtils.join("/", new String[]{"printers", str, "tasks"}); String jSONObject2 = jSONObject.toString(); AnonymousClass3 r5 = new c<JSONObject>() { /* class defpackage.eao.AnonymousClass3 */ @Override // defpackage.eao.c public final void c(Throwable th) { if (cVar != null) { cVar.c(th); } } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // defpackage.eao.c public final /* synthetic */ void y(JSONObject jSONObject) { try { String string = jSONObject.getString(SpeechEvent.KEY_EVENT_RECORD_DATA); if (cVar != null) { cVar.y(string); } } catch (JSONException e) { c(e); } } }; return a(new a(1, TextUtils.join("/", new String[]{"https://moapi.wps.cn/printerServe/v1", join}), jSONObject2, this.mToken, r5), str2.intern()); } /* access modifiers changed from: package-private */ public Object a(vys<?> vys, final Object obj) { vys.mTag = obj; if (this.ewB == null) { this.ewB = vzv.ig(OfficeApp.arx()); this.ewB.start(); } this.ewB.a(new vyt.a() { /* class defpackage.eao.AnonymousClass5 */ @Override // defpackage.vyt.a public final boolean a(vys<?> vys) { if (vys.mTag == null) { return false; } return vys.mTag == obj || vys.mTag.equals(obj); } }); this.ewB.e(vys); return obj; } public final int az(String str, String str2) throws ExecutionException, InterruptedException, JSONException { JSONObject aA = aA(str, str2); if (aA == null) { return -1; } try { return aA.getInt(NotificationCompat.CATEGORY_STATUS); } catch (JSONException e) { throw e; } } public final List<String> mD(String str) throws Throwable { final vzt fVu = vzt.fVu(); a(str, new c<List<String>>() { /* class defpackage.eao.AnonymousClass2 */ @Override // defpackage.eao.c public final void c(Throwable th) { fVu.a(new vyz(th)); } /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */ @Override // defpackage.eao.c public final /* synthetic */ void y(List<String> list) { fVu.onResponse(list); } }); do { } while (!fVu.isDone()); try { return (List) fVu.get(); } catch (ExecutionException e) { throw e.getCause(); } } }